package knowse.app;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class HeatMapData {
	
    private ArrayList<ArrayList> data;
    private ArrayList<String> labels;
    
    private boolean isDataSet = false;
    
	float[][] testData = {{0.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f}, 
			   {10.0f, 80.0f, 12.0f, 12.0f, 6.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f}, 
				{10.0f, 80.0f, 12.0f, 12.0f, 6.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f}};

	String[] testLabels  = {"KnowSE","TestSE","OtherSE"};
	
	public HeatMapData ()
	{
		//Old stuff
		//float[][] data = {{0.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f}, 
        //				   {10.0f, 80.0f, 12.0f, 12.0f, 6.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f}, 
        //					{10.0f, 80.0f, 12.0f, 12.0f, 6.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f}};

        //String[] labels  = {"KnowSE","TestSE","OtherSE"};
        
        //this.data = data;
        //this.labels = labels;
		
        //Setup example labels			
		//labels = new ArrayList();
        //labels.add("KnowSE");
        //labels.add("TestSE");
        //labels.add("OtherSE");
        
        //Setup example data
        //data = new ArrayList();
        //data.add(new ArrayList<Float>(Arrays.asList(0.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f)));  
        //data.add(new ArrayList<Float>(Arrays.asList(0.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f)));  
        //data.add(new ArrayList<Float>(Arrays.asList(0.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f, 100.0f, 2.0f, 3.0f, 4.0f, 5.0f)));
	}

	public void addRow(String label, float value) {
		//We don't want to use default test data!
		isDataSet = true;
		
		//If it is the first time we add data for label
		labels = new ArrayList();
		data = new ArrayList();
		ArrayList tempData;
		if(!labels.contains(label)) {
			labels.add(label);
			tempData = new ArrayList();
			tempData.add(value);
			data.add(tempData);
		} else {
			int index = labels.indexOf(label);
			tempData = data.get(index);
			tempData.add(value);
			data.set(index, tempData);
		}
	}
	
	public float[][] getData() {
		//No data is set, returning test data
		if (!isDataSet) {
			return testData;
		}
		
		float [][] returnData = new float[data.size()][];
		int arraySize = data.size();
		
		for(int i = 0; i < arraySize; i++)
		{
			ArrayList subArray = data.get(i);
			int subArraySize = subArray.size();
			
			returnData[i] = new float[subArraySize];
			for(int j = 0; j < subArraySize; j++) {
				returnData[i][j] = (Float) subArray.get(j);
			}
			
		}

		return returnData;
	}
	
	public String[] getLabels() {
		//No data is set, returning test data
		if (!isDataSet) {
			return testLabels;
		}
		
		return labels.toArray(new String[labels.size()]);
	}
}